package com.itheima.health.controller;

import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.OrderSetting;
import com.itheima.health.pojo.OrderSettingVO;
import com.itheima.health.service.OrderSettingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.List;
@Slf4j
@RequestMapping("/ordersetting")
@RestController
public class OrderSettingController {
    @Resource
    private OrderSettingService orderSettingService;
    @GetMapping("/getOrderSettingByMonth")
    public Result getOrderSettingByMouth(Integer year, Integer month){
        LocalDate beginTime = LocalDate.of(year, month, 1);
        LocalDate endTime = LocalDate.of(year, month, 28);
        if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
            endTime = LocalDate.of(year, month, 31);
        }else if(month == 4 || month == 6 || month ==9 || month == 11){
            endTime = LocalDate.of(year, month, 30);
        }
        List<OrderSettingVO> list = orderSettingService.getOrderSettingByMouth(beginTime,endTime);
        return new Result(true, MessageConst.GET_ORDERSETTING_SUCCESS,list);
    }
    @PostMapping("/editNumberByDate")
    public Result editNumberByDate(@RequestBody OrderSetting orderSetting){
        orderSettingService.editNumberByDate(orderSetting);
        return new Result(true,MessageConst.ORDERSETTING_SUCCESS);
    }
    @PostMapping("/upload")
    public Result upload( MultipartFile excelFile){
        log.warn("{}",excelFile.getOriginalFilename());
        return new Result(true,MessageConst.IMPORT_ORDERSETTING_SUCCESS);
    }
}
